#pragma once

#include "LogFile.h"

class CLogManager
{
public:
	CLogManager();
	~CLogManager();

	static LPCWSTR GetLogPath() { return m_szLogPath; }

	bool Init();
	void Exit();
	void WriteLine(LPCVOID lpAddress, const std::string& strLine);

private:
	void OnTimer();
	void DelExpiredLogs();

	class CModuleKey
	{
	public:
		CModuleKey(LPCVOID lpAddress, DWORD dwSize = 0)
			: m_lpAddress(lpAddress)
			, m_dwSize(dwSize)
		{
		}

		bool operator<(const CModuleKey& key) const
		{
			return (LPCSTR)m_lpAddress + m_dwSize <= key.m_lpAddress;
		}

	private:
		LPCVOID m_lpAddress;
		DWORD   m_dwSize;
	};

	static wchar_t   m_szLogPath[MAX_PATH];

	std::atomic_bool m_bWriting;
	std::atomic_bool m_bFirstRun;
	PTP_TIMER        m_pTpTimer;
	SRWLOCK          m_SRWLock = SRWLOCK_INIT;
	std::map<CModuleKey, CLogFile> m_mapLogFiles;
};
